package com.gitee.hljdrl.lite.config;

import java.util.HashMap;
import java.util.Map;

public class AppConf {

    public static boolean DEBUG = false;
    public static String PKG_NAME;
    public static String VERSION_NAME;
    public static int VERSION_CODE;
    public static String APP_NAME;
    private final Map<String, Object> config;


    /**
     * @param debug       apk包debug开关
     * @param app_name    app的名字
     * @param pkg         apk的applicationId
     * @param versionCode apk的VersionCode
     * @param versionName apk的VersionName
     * @param map         app模块BuildConfig
     */
    public AppConf(boolean debug,String app_name, String pkg, int versionCode, String versionName, Map<String, Object> map) {
        AppConf.DEBUG = debug;
        AppConf.PKG_NAME = pkg;
        AppConf.VERSION_CODE = versionCode;
        AppConf.VERSION_NAME = versionName;
        APP_NAME = app_name;
        //------------------------------------
        config = new HashMap();
        if (map != null && !map.isEmpty()) {
            config.putAll(map);
        }
    }

    /**
     * 获取 app模块BuildConfig文件内容
     *
     * @param key
     * @return
     */
    public final String conf(String key) {
        Object value = config.get(key);
        if (value != null) {
            return value.toString();
        }
        return null;
    }

    /**
     * 读取app打包配置参数
     *
     * @param key
     * @param defaultValue 默认参数
     * @return
     */
    public final String conf(String key, String defaultValue) {
        Object value = config.get(key);
        if (value != null) {
            return value.toString();
        }
        return defaultValue;
    }

    public final boolean enable(String key) {
        Object value = config.get(key);
        if (value != null) {
            try {
                if (value instanceof Boolean) {
                    Boolean ret = (Boolean) value;
                    return ret.booleanValue();
                }
            } catch (Exception ex) {
            }
        }
        return false;
    }
}
